<template>
  <el-table :data="tableData6" border show-summary style="width: 100%" :span-method="objectSpanMethod">
    <el-table-column prop="date" label="收房日期" width="180"></el-table-column>
    <el-table-column prop="num" label="订单数" width="100"></el-table-column>
    <el-table-column prop="name" label="楼盘" width="180"></el-table-column>
    <el-table-column prop="region" label="城市划区" width="180"></el-table-column>
    <el-table-column prop="amount2" label="订单数"></el-table-column>
  </el-table>
</template>
<script>
export default {
    data() {
      return {
        tableData6: [{
            date:'2019-02-28',
            num:'123',
            name: '复地上城',
            region:'主城区',
            amount2:12,
        },{
            date:'2019-02-28',
            num:'123',
            name: '复地上城',
            region:'主城区',
            amount2:12,
        }, {
            date:'2019-02-28',
            num:'123',
            name: '复地上城',
            region:'主城区',
            amount2:12,
        }, {
            date:'2019-02-28',
            num:'123',
            name: '复地上城',
            region:'主城区',
            amount2:12,
        }, {
            date:'2019-02-28',
            num:'123',
            name: '复地上城',
            region:'主城区',
            amount2:12,
        }, ]
      };
    },
    methods: {
      getSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' 元';
          } else {
            sums[index] = 'N/A';
          }
        });

        return sums;
      },
      objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 0 || columnIndex === 1) {
          if (rowIndex % 2 === 0) {
            return {
              rowspan: 2,
              colspan: 1
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }
      }
    }
  };
</script>
<style lang="less" scoped>
</style>
